<?php

	// TITLE: Demographic AUTO MODEL
	// FILE: scaffolding/model/demographic.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createDemographic = function($con, $demographic) {
		$sql = 'INSERT INTO demographic (demographic_id, homeowner_id) VALUES (';
		$sql .= $demographic->getDemographicId() . ', ';
		$sql .= $demographic->getHomeownerId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readDemographic = function($con, $id) {
		$sql = 'SELECT * FROM demographic WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$demographic = new Demographic();
			$demographic->setDemographicId($dbio->select($readDemographic(result[0])));
			$demographic->setHomeownerId($dbio->select($readHomeowner(result[1])));
		} else {
			$demographic = false;
		}
		return $demographic;
	};

	$updateDemographic = function($con, $demographic) {
		$sql = 'UPDATE demographic SET ';
		$sql .= 'demographic_id = ' . $demographic->getDemographicId() . ', ';
		$sql .= 'homeowner_id = ' . $demographic->getHomeownerId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteDemographic = function($con, $id) {
		$sql = 'DELETE FROM demographic WHERE demographic_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listDemographic = function($con) {
		$sql = 'SELECT * FROM demographic';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$demographics = array();
			while ($result = mysqli_fetch_array($results)) {
				$demographic = new Demographic();
				$demographic->setDemographicId($dbio->select($readDemographic(result[0])));
				$demographic->setHomeownerId($dbio->select($readHomeowner(result[1])));
				$demographics[] = demographic;
			}// end while
		} else {
			$demographics = false;
		}
		return $demographics;
	};

